package com.xjh.basestudy.javabase.Internetprogram;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class InetAddress1 {
    public static void main(String[] args) throws UnknownHostException {
        //确定主机的ip地址或者计算机名称
        InetAddress address = InetAddress.getByName("xjh");
//        InetAddress address = InetAddress.getByName("169.254.196.247");//推荐

        //获取ip地址的主机名
        String name = address.getHostName();
        //获取ip地址字符串
        String ip = address.getHostAddress();
        System.out.println("主机名："+name);
        System.out.println("ip地址："+ip);
    }
}
